import _ from 'lodash';
import { HttpResponse } from 'msw';

export const dyadicArr = (array, num) => {
  const newArr = [];
  const handler = (arr) => {
    if (arr.length > num) {
      newArr.push(arr.splice(0, num));
      handler(arr);
    } else {
      newArr.push(arr);
    }
  };
  handler(_.cloneDeep(array));
  return newArr;
};

export const JsonResult = {
  error(msg: string) {
    return HttpResponse.json({
      code: 0,
      msg,
    });
  },
  sucess(data: any) {
    return HttpResponse.json({
      code: 1,
      data,
    });
  },
};
